<?php

/**
 * This is the model class for table "tbl_jobs_class".
 *
 * The followings are the available columns in table 'tbl_jobs_class':
 * @property integer $id
 * @property string $description
 * @property integer $inactive
 * @property string $defworkcompid
 */
class JobsClass extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return JobsClass the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_jobs_class';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('description, inactive', 'required'),
			array('inactive', 'numerical', 'integerOnly'=>true),
			array('description', 'length', 'max'=>60),
			array('defworkcompid', 'length', 'max'=>10),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, description, inactive, defworkcompid', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'description' => 'Description',
			'inactive' => 'Inactive',
			'defworkcompid' => 'Defworkcompid',
		);
	}

	public static function getList(){
            $list=JobsClass::model()->findAll('inactive=0');
            $rs=array(''=>'N/A');
            foreach($list as $item){
                $rs[$item->id]=$item->description;
            }
            return $rs;
        }
        public static function getText($id){
            $data=Yii::app()->db->createCommand('select description from tbl_jobs_class where id=:id')->bindValue('id', $id)->queryScalar();
            if($data!==false)return $data;
            return NULL;
        }
        
        public function getInactiveList(){
            return array(
                -1=>'Pending',
                0=>'Active',
                1=>'Inactive'
            );
        }
        public function getInactiveText(){
            return isset($this->inactiveList[$this->inactive])?$this->inactiveList[$this->inactive]:NULL;
        }
}